<!DOCTYPE html>
<html>
  <head>
  	<div th:include="base-libs :: base-libs" />
    <title>双向转诊台账</title>
    <style>
    	.laydate-icon{
    		height:30px;
    		border-color:#B6B6B6
    	}
    	.north{
    		padding:8px 0px;
    		background:#f9f9f9;
    		overflow:hidden;
    	}
    	.tabs-wrap>.tabs>li>a{
			border-left:1px solid #438EB9!important;
			border-right:1px solid #438EB9!important;
			border-top:1px solid #438EB9!important;
		}
		.spanBtn{
			font-weight: bold;
			color: blue;
			cursor:pointer;
		}
		.timeLeft{
			width:36% !important;
		}
		.timeRight{
			width:36% !important;
			float:right;
		}
		.timeSpan{
			display:inline-block;
			width:4%;
			text-align:right;
		}
    </style>
	<script>
        var zzlxArr,jjcdArr;//转诊类型Arr，紧急程度Arr
        var sfqyArr = [{XMDM:'1',"XMMC":'已签约'},{XMDM:'2',"XMMC":'未签约'}];
        var sflyArr = [{XMDM:'1',"XMMC":'已履约'},{XMDM:'2',"XMMC":'未履约'}];

		var showTabIndex = StoreCache.removeCache('showTabIndex');
		$(function(){
			initView();
            $(this).registerManagerPage({cacheTables:["TB_ZY_JJCD"],callback:initData});
		})
		
		function initData(){
            queryCount(); //页签数量
            zzlxArr = StoreCache.getCache("TB_ZY_ZZLX").data;
            jjcdArr = StoreCache.getCache("TB_ZY_JJCD").data;
            initTableMethod.zcTb();
            $("body").css("visibility","visible");
		}
		
		function initView(){
		    //回车查询
			enterToQuery(queryTableData);

			$('#tabs').tabs({
				border: true,
			    fit: true,
			    tabWidth: "150",
				onSelect: function(title,index){
					var nowSelectTab = $(this).tabs('getTab',index); //获取到当前激活的tab
					var tableId = nowSelectTab.find("table").eq(1).attr("id");
					if(!StringUtils.isEmpty(tableId)){
						initTableMethod[tableId](); //初始化table
					}
				}
			})

			if(!StringUtils.isEmpty(showTabIndex)){
				$('#tabs').tabs('select',parseInt(showTabIndex));
			}

            /** 修改记录 */
            $("body").on("click",".btnXg",function(){
                var index = $('#tabs').tabs('getTabIndex',$('#tabs').tabs('getSelected'));
                var select = $("#" + ['zcTb','zrTb'][index]).datagrid("getSelected");
                StoreCache.setCache("sxzztzData",select);

                parent.layer.open({
                    type: 2,
                    area: ["60%", "275px"],
                    content: contextRoot + 'sxzztz/update.html',
                    scrollbar: false,
                    resize: false,
                    title:'修改',
                    end: function(){
                        if(StoreCache.removeCache("refresh")){
                            queryTableData();
                        }
                    }
                });
            })

            /** 删除记录 */
            $("body").on("click",".btnSc",function(){
                var delParams = {ID: $(this).attr("id")}
                $.QuickAlert.alertConfirm({
                    content : "删除后不可恢复，是否确认删除该数据？",
                    callback : function() {

                        $.QuickRemote.AjaxJson("delete", function (result) {
                            if(result.state){
                                $.QuickAlert.alertNormal(result.info, {callback: function(){
                                    queryTableData();
                                }});
                            }else{
                                $.QuickAlert.alertFail({content: result.info});
                            }
                        }, delParams);
                    }
                })
            })
            //开始时间与结束时间的互相限制
            timeSetting("startTimeZc","stopTimeZc");
            timeSetting("startTimeZr","stopTimeZr");
		}

        //时间段互相限制
        function timeSetting(startTagId,endTagId){
            var startTimeObj = {
                elem: '#'+ startTagId ,
                choose: function(datas){
                    endTimeObj.min = datas;
                }
            };
            laydate(startTimeObj);

            var endTimeObj = {
                elem: '#'+ endTagId,
                choose: function(datas){
                    startTimeObj.max = datas;
                }
            };
            laydate(endTimeObj);
        }

		/** 查询数据  */
		function queryTableData(){
            var index = $('#tabs').tabs('getTabIndex',$('#tabs').tabs('getSelected'));
			$("#"+['zcTb','zrTb'][index]).datagrid("load");
		}

        /** 跳转到新增页面 */
        function toManager(row){
            var tabIndex = $('#tabs').tabs('getTabIndex',$('#tabs').tabs('getSelected'));
            StoreCache.setCache("showTabIndex",tabIndex);
            $.QuickUrlUtils.redirectUrl(["managerZc.html","managerZr.html"][tabIndex]);
        }

        function queryCount(){
            $.QuickRemote.AjaxJson(contextRoot + "sxzztz/queryCount", function(result){
                if(result.state){
                    $("#ZCNUM").html(result.ZCNUM);
                    $("#ZRNUM").html(result.ZRNUM);
                }else{
                    $.QuickAlert.alertFail({content: result.info});
                }
            }, null);
		}

		/** 初始化table的方法  */
		var initTableMethod = {
				//转出列表
				zcTb: function(){
					var query = $('#zcTb').data("query");
	    			if(!query){
	    				$('#zcTb').data("query",true);
	    			}else{
	    				return;
	    			}
	    			$('#zcTb').datagrid({
							idField : "ID",
							striped : true,
							clickToSelect: true,
							fit:true,
							fitColumns: true,
							singleSelect: true,
							pagination : true,
							pageList: [10, 20, 30, 50, 100],
							scrollBarSize:10,
							columns:[[
						   				{field:'FQZZSJ', title:'申请转诊时间', width: 80, align: 'center',formatter:function(value){
							    			if(value) return value.substring(0,10);
										}}
										,{field:'XM', title:'患者姓名', width: 60, align: 'center'}
										,{field:'SFZH', title:'证件号码', width: 110, align: 'center',formatter:function(value){
											if(!StringUtils.isEmpty(value)){
												var reg = /.{8}$/;
												return value.replace(reg,'********')
											}
										}}
										,{field:'ZRYY', title:'转入医院', width: 140, align: 'center',formatter:function(value){
											return '<span title="' + value + '">' + value + '</span>'
										}}
										,{field:'ZRKS', title:'转入科室', width: 140, align: 'center',formatter:function(value){
											return '<span title="' + value + '">' + value + '</span>'
										}}
										,{field:'ZZLX', title:'转诊类型', width: 60, align: 'center',formatter:function(value){
											$.each(zzlxArr, function(){
											    if(this.XMDM==value){
											        value = this.XMMC;
													return false;
												}
											})
											return value;
										}}
										,{field:'JJCD', title:'紧急程度', width: 60, align: 'center',formatter:function(value){
											$.each(jjcdArr, function(){
												if(this.XMDM==value){
													value = this.XMMC;
													return false;
												}
											})
											return value;
										}}
										,{field:'SFLY', title:'是否履约', width: 60, align: 'center',formatter:function(value){
											$.each(sflyArr, function(){
												if(this.XMDM==value){
													value = this.XMMC;
													return false;
												}
											})
											return value;
										}}
										,{field:'LYSJ', title:'履约时间', width: 65, align: 'center',formatter:function(value){
											if(value) return value.substring(0,10);
										}}
										,{field:'SFQY', title:'是否签约', width: 60, align: 'center',formatter:function(value){
											$.each(sfqyArr, function(){
												if(this.XMDM==value){
													value = this.XMMC;
													return false;
												}
											})
											return value;
										}}
										,{field:'cz', title:'操作', width: 50, align: 'center',formatter:function(value,row){
											var xg = '<span class="btnXg spanBtn">修改</span>';
											var sc = '<span class="btnSc spanBtn" id="' + row.ID + '">删除</span>';
											return xg + "&nbsp;&nbsp;" + sc;
										}}
							]],
							onBeforeLoad: function(params){
							    params.ZZBS = 1;
								getContainerDataByClassName('nbCondition','condition',params);//查询条件
							},
							onLoadSuccess: function(data){
// 								alert(JSON.stringify(data))
							},
							url: contextRoot+"sxzztz/queryPage.service"
					})
				},
				//转入列表
				zrTb: function(){
					var query = $('#zrTb').data("query");
	    			if(!query){
	    				$('#zrTb').data("query",true);
	    			}else{
	    				return;
	    			}
	    			$('#zrTb').datagrid({
							idField : "ID",
							striped : true,
							clickToSelect: true,
							fit:true,
							fitColumns: true,
							singleSelect: true,
							pagination : true,
							pageList: [10, 20, 30, 50, 100],
							scrollBarSize:10,
							columns:[[
								{field:'ZZYYSJ', title:'转诊预约时间', width: 80, align: 'center',formatter:function(value){
                                    if(value) return value.substring(0,10);
                                }}
								,{field:'XM', title:'患者姓名', width: 60, align: 'center'}
								,{field:'SFZH', title:'证件号码', width: 110, align: 'center',formatter:function(value){
                                    if(!StringUtils.isEmpty(value)){
                                        var reg = /.{8}$/;
                                        return value.replace(reg,'********')
                                    }
                                }}
								,{field:'ZCYY', title:'转出医院', width: 140, align: 'center',formatter:function(value){
							    	return '<span title="' + value + '">' + value + '</span>'
								}}
								,{field:'ZCKS', title:'转出科室', width: 140, align: 'center',formatter:function(value){
                                    return '<span title="' + value + '">' + value + '</span>'
                                }}
								,{field:'ZZLX', title:'转诊类型', width: 60, align: 'center',formatter:function(value){
                                    $.each(zzlxArr, function(){
                                        if(this.XMDM==value){
                                            value = this.XMMC;
                                            return false;
                                        }
                                    })
                                    return value;
                                }}
								,{field:'JJCD', title:'紧急程度', width: 60, align: 'center',formatter:function(value){
                                    $.each(jjcdArr, function(){
                                        if(this.XMDM==value){
                                            value = this.XMMC;
                                            return false;
                                        }
                                    })
                                    return value;
                                }}
								,{field:'SFLY', title:'是否履约', width: 60, align: 'center',formatter:function(value){
                                    $.each(sflyArr, function(){
                                        if(this.XMDM==value){
                                            value = this.XMMC;
                                            return false;
                                        }
                                    })
                                    return value;
                                }}
								,{field:'LYSJ', title:'履约时间', width: 65, align: 'center',formatter:function(value){
                                    if(value) return value.substring(0,10);
                                }}
								,{field:'SFQY', title:'是否签约', width: 60, align: 'center',formatter:function(value){
                                    $.each(sfqyArr, function(){
                                        if(this.XMDM==value){
                                            value = this.XMMC;
                                            return false;
                                        }
                                    })
                                    return value;
                                }}
								,{field:'cz', title:'操作', width: 50, align: 'center',formatter:function(value,row){
                                    var xg = '<span class="btnXg spanBtn">修改</span>';
                                    var sc = '<span class="btnSc spanBtn" id="' + row.ID + '">删除</span>';
                                    return xg + "&nbsp;&nbsp;" + sc;
								}}
							]],
							onBeforeLoad: function(params){
                                params.ZZBS = 2;
								getContainerDataByClassName('ydqCondition','condition',params);//查询条件
							},
							url: contextRoot+"sxzztz/queryPage.service"
					})
				}
		}
		
	</script>
  </head>
  
  <body style="visibility:hidden">
		<div id="tabs" class="easyui-tabs" fit="true" border="false">
			<div title="转出(<span style='color:red' id='ZCNUM'>0</span>)">
				<div class="easyui-layout" border="false" fit="true">
					<div region="north" class="north" border="false" style="height:60px">
						<form action="downloadQycx.service" method="post" enctype="multipart/form-data" id="downloadAllForm">
							<table class="form-table" id="nbCondition">
								<tr>
									<td class="td-text">患者姓名：</td>
									<td class="td-content">
										<input class="form-control condition"  name="XM" style="width: 100%;">
									</td>
									<td class="td-text">转诊类型：</td>
									<td class="td-content">
										<select name="ZZLX" class="form-control condition" style="width: 100%;" cacheTable="TB_ZY_ZZLX">
											<option value="">请选择</option>
										</select>
									</td>
									<td class="td-text">申请转诊时间：</td>
									<td class="td-content">
										<input id="startTimeZc" name="FQZZSJ_start" class="laydate-icon condition timeLeft"/>
										<span class="timeSpan">-</span>
										<input id="stopTimeZc" name="FQZZSJ_end" class="laydate-icon condition timeRight"/>
									</td>
									<td class="td-text" style="text-align:center;width:170px">
										<button class="btn btn-info btnCx" type="button" onclick="queryTableData('zcTb')">查询</button>
										<button class="btn btn-info" type="button" onclick="toManager()">新增</button>
									</td>
								</tr>
							</table>
						</form>
					</div>
					<div region="center" border="false">
						<table id="zcTb" border="false"></table>
					</div>
				</div>
			</div>
			
			
			
			
			
			<div title="转入(<span style='color:red' id='ZRNUM'>0</span>)">
				<div class="easyui-layout" border="false" fit="true">
					<div region="north" class="north" border="false" style="height:60px">
						<form action="downloadQycx.service" method="post" enctype="multipart/form-data" id="downloadYdqForm">
							<table class="form-table" id="ydqCondition">
								<tr>
									<td class="td-text">患者姓名：</td>
									<td class="td-content">
										<input class="form-control condition"  name="XM" style="width: 100%;">
									</td>
									<td class="td-text">转诊类型：</td>
									<td class="td-content">
										<select name="ZZLX" class="form-control condition" style="width: 100%;" cacheTable="TB_ZY_ZZLX">
											<option value="">请选择</option>
										</select>
									</td>
									<td class="td-text">转诊预约时间：</td>
									<td class="td-content">
										<input id="startTimeZr" name="ZZYYSJ_start" class="laydate-icon condition timeLeft"/>
										<span class="timeSpan">-</span>
										<input id="stopTimeZr" name="ZZYYSJ_end" class="laydate-icon condition timeRight"/>
									</td>
									<td class="td-text" style="text-align:center;width:170px">
										<button class="btn btn-info btnCx" type="button" onclick="queryTableData('zrTb')">查询</button>
										<button class="btn btn-info" type="button" onclick="toManager()">新增</button>
									</td>
								</tr>
							</table>
						</form>
					</div>
					<div region="center" border="false">
						<table id="zrTb" border="false"></table>
					</div>
				</div>
			</div>
		</div>
  </body>
</html>
